package 一六;

/**
 * Created by lenovo on 2017/3/14.
 */
public class q7 {

    /**
     * 相邻矩阵
     */
    static int cc[][] = {
            {1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
            {1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
            {0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0},
            {0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0},
            {1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0},
            {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0},
            {0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0},
            {0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1},
            {0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0},
            {0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0},
            {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1},
            {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1},
    };

    public static void main(String[] args) {
        int a, b, c, d, e, sum = 0;
        for (a = 0; a < 8; a++) {
            for (b = a + 1; b < 9; b++) {
                for (c = b + 1; c < 10; c++) {
                    for (d = c + 1; d < 11; d++) {
                        for (e = d + 1; e < 12; e++) {
                            int z[] = {a, b, c, d, e};
                            if (f(z)) {
                                System.out.println(a + 1 + " " + (b + 1) + " " + (c + 1) + " " + (d + 1) + " " + (e + 1));
                                sum++;
                            }
                        }
                    }
                }
            }
        }
        System.out.println(sum);
    }

    /**
     * 验证函数，查看是否满足条件
     * @param a
     * @return
     */
    private static boolean f(int[] a) {
        int is[] = new int[5];
        is[0] = 1;
        g(a, 0, is);
        int zz = 0;
        for (int i : is) {
            if (i == 1) zz++;
        }
        if (zz == 5) return true;
        return false;
    }

    /**
     * 深度遍历
     * @param a
     * @param b
     * @param c
     */
    private static void g(int[] a, int b, int[] c) {
        for (int i = 0; i < c.length; i++) {
            if (c[i] == 0) {
                if (cc[a[b]][a[i]] == 1) {
                    c[i] = 1;
                    g(a, i, c);
                }
            }
        }
    }
}
